<template>
  <div class="app-container">
    <!-- 查询区域 -->
    <el-form :inline="true" class="demo-form-inline" size="mini">
      <el-form-item label="污染源名称：">
        <el-input
          v-model="queryParams.pollutename"
          placeholder="请输入污染源名称"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="行政区划：">
        <el-select
          v-model="queryParams.countycode"
          placeholder="请选择行政区划"
          clearable
        >
          <el-option
            v-for="item in regionList"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="是否涉水污染源：">
        <el-select
          v-model="queryParams.waterrelate"
          placeholder="请选择是否涉水污染源"
          clearable
        >
          <el-option label="是" value="1"></el-option>
          <el-option label="否" value="0"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="是否在线监测：">
        <el-select
          v-model="queryParams.isonlinemonitoringent"
          placeholder="请选择是否在线监测"
          clearable
        >
          <el-option label="是" value="1"></el-option>
          <el-option label="否" value="0"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="是否污水处理厂：">
        <el-select
          v-model="queryParams.issewagefarm"
          placeholder="请选择是否污水处理厂"
          clearable
        >
          <el-option label="是" value="1"></el-option>
          <el-option label="否" value="0"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="污染源类型：">
        <el-select
          v-model="queryParams.enterprisetype"
          placeholder="请选择污染源类型"
          clearable
        >
          <el-option
            v-for="item in dict.type.sys_pollutions_type"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="排污许可证：">
        <el-input
          v-model="queryParams.outpermitnb"
          placeholder="请输入排污许可证"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="统一社会信用代码：">
        <el-input
          v-model="queryParams.socialcode"
          placeholder="请输入统一社会信用代码"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作按钮区域 -->
    <div style="margin-bottom: 15px">
      <el-button type="primary" size="small" @click="handleAdd">新增</el-button>
      <!-- <el-button type="success" size="small" @click="handleEdit">修改</el-button> -->
      <el-button type="danger" size="small" @click="handleDelete(null)"
        >删除</el-button
      >
      <el-button type="warning" size="small" @click="handleExport"
        >导出</el-button
      >
      <!-- <el-button type="info" size="small" @click="handleImport">导入</el-button> -->
      <!-- <el-button type="text" size="small" @click="downloadTemplate">下载模板</el-button> -->
    </div>

    <!-- 数据表格 -->
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="pollutename"
        label="污染源名称"
        min-width="180"
        show-overflow-tooltip
      ></el-table-column>

      <el-table-column
        prop="socialcode"
        label="统一社会信用代码"
        min-width="180"
      ></el-table-column>

      <el-table-column
        prop="county"
        label="行政区划"
        min-width="120"
      ></el-table-column>

      <el-table-column
        prop="industrytypename"
        label="行业类别"
        min-width="120"
      ></el-table-column>

      <el-table-column
        prop="lawperson"
        label="法定代表人"
        min-width="120"
      ></el-table-column>

      <el-table-column
        prop="outpermitnb"
        label="排污许可证编号"
        min-width="180"
      ></el-table-column>

      <el-table-column
        prop="rivername"
        label="污水受纳水体"
        min-width="120"
      ></el-table-column>

      <el-table-column prop="destination" label="污水去向" min-width="120">
        <template slot-scope="scope">
          <template v-for="item in destinationList">
            <span v-if="item.value == scope.row.destination">{{
              item.label
            }}</span>
          </template>
        </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" width="120">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleEditRow(scope.row)"
            >修改</el-button
          >
          <el-button size="mini" type="text" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <div style="margin-top: 20px; text-align: right">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- 新增/编辑弹窗 -->
    <el-dialog
      title="添加污染源档案"
      :visible.sync="dialogVisible"
      width="60%"
      center
      append-to-body
    >
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        label-width="180px"
        size="mini"
      >
        <!-- 第一行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="污染源名称：" prop="pollutename">
              <el-input
                v-model="formData.pollutename"
                placeholder="请输入污染源名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="污染源编码：" prop="pollutenb">
              <el-input
                v-model="formData.pollutenb"
                placeholder="请输入污染源编码"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第二行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="曾用名：" prop="epoldname">
              <el-input
                v-model="formData.epoldname"
                placeholder="请输入曾用名"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- county 所属区县 -->
            <el-form-item label="行政区划：" prop="countycode">
              <el-select
                v-model="formData.countycode"
                placeholder="请选择行政区划"
                style="width: 100%"
                @change="
                  formChange($event, 'code', { county: 'name' }, regionList)
                "
              >
                <el-option
                  v-for="item in regionList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第三行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="详细地址：" prop="polluteaddress">
              <el-input
                v-model="formData.polluteaddress"
                placeholder="请输入详细地址"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="流域：" prop="watershed">
              <el-select
                v-model="formData.watershed"
                placeholder="请选择流域"
                style="width: 100%"
              >
                <el-option
                  v-for="item in basinList"
                  :key="item.id"
                  :label="item.basinname"
                  :value="item.id"
                ></el-option>
              </el-select>
              <!-- <el-input v-model="formData.watershed" placeholder="请输入流域"></el-input> -->
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第四行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="统一社会信用代码：" prop="socialcode">
              <el-input
                v-model="formData.socialcode"
                placeholder="请输入统一社会信用代码"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第五行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="经度：" prop="longitude">
              <el-input
                v-model="formData.longitude"
                placeholder="请输入经度"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度：" prop="latitude">
              <el-input
                v-model="formData.latitude"
                placeholder="请输入纬度"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第六行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <!-- industrytypename: 行业类型编码-->
            <el-form-item label="行业类别：" prop="industrytypecode">
              <el-select
                v-model="formData.industrytypecode"
                placeholder="请选择行业类别"
                style="width: 100%"
                @change="
                  formChange(
                    $event,
                    'code',
                    { industrytypename: 'dicname' },
                    industryList
                  )
                "
              >
                <el-option
                  v-for="item in industryList"
                  :label="item.dicname"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="污染源类型：" prop="wrylx">
              <el-select
                v-model="formData.wrylx"
                placeholder="请选择污染源类型"
                style="width: 100%"
              >
                <el-option
                  v-for="item in dict.type.sys_pollutions_type"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第七行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="污水去向：" prop="destination">
              <el-select
                v-model="formData.destination"
                placeholder="请选择污水去向"
                style="width: 100%"
              >
                <el-option
                  v-for="item in destinationList"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- epstate: 企业状态名称 -->
            <el-form-item label="企业状态：" prop="epstatecode">
              <el-select
                v-model="formData.epstatecode"
                placeholder="请选择企业状态"
                style="width: 100%"
                @change="
                  formChange(
                    $event,
                    'value',
                    { epstate: 'label' },
                    dict.type.company_status
                  )
                "
              >
                <el-option
                  v-for="item in dict.type.company_status"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第八行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="成立日期：" prop="establishDate">
              <el-date-picker
                v-model="formData.establishDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择成立日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="注册资本：" prop="registercapital">
              <el-input
                v-model="formData.registercapital"
                placeholder="请输入注册资本"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="实缴资本：" prop="actualcapital">
              <el-input
                v-model="formData.actualcapital"
                placeholder="请输入注册资本"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工商注册号：" prop="businessnum">
              <el-input
                v-model="formData.businessnum"
                placeholder="请输入工商注册号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第九行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="组织机构代码：" prop="organizationcode">
              <el-input
                v-model="formData.organizationcode"
                placeholder="请输入组织机构代码"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法定代表人：" prop="lawperson">
              <el-input
                v-model="formData.lawperson"
                placeholder="请输入法定代表人"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="联系人：" prop="linkman">
              <el-input
                v-model="formData.linkman"
                placeholder="请输入联系人"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话：" prop="telephone">
              <el-input
                v-model="formData.telephone"
                placeholder="请输入联系电话"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十一行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="排污许可证编号：" prop="outpermitnb">
              <el-input
                v-model="formData.outpermitnb"
                placeholder="请输入排污许可证编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--rivername: 所属河流名称  riverid  河流ID-->
            <el-form-item label="污水受纳水体：" prop="riverid">
              <el-select
                v-model="formData.riverid"
                placeholder="请选择污水受纳水体"
                style="width: 100%"
                @change="
                  formChange(
                    $event,
                    'id',
                    { rivername: 'rivername' },
                    riverList
                  )
                "
              >
                <el-option
                  v-for="item in riverList"
                  :label="item.rivername"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十二行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否废水企业：" prop="waterrelate">
              <el-select
                v-model="formData.waterrelate"
                placeholder="请选择是否废水企业"
                style="width: 100%"
              >
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否在线企业：" prop="isonlinemonitoringent">
              <el-select
                v-model="formData.isonlinemonitoringent"
                placeholder="请选择是否在线企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十三行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否污水处理厂：" prop="issewagefarm">
              <el-select
                v-model="formData.issewagefarm"
                placeholder="请选择是否污水处理厂"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 没有字段 -->
            <!-- <el-form-item label="污水处理厂：" prop="sewageFarm">
              <el-select v-model="formData.sewageFarm" placeholder="请选择污水处理厂" style="width: 100%;">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item> -->
          </el-col>
        </el-row>

        <!-- 第十四行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否风险源：" prop="ifrisk">
              <el-select
                v-model="formData.ifrisk"
                placeholder="请选择是否风险源"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否危废企业：" prop="ishazardouswaste">
              <el-select
                v-model="formData.ishazardouswaste"
                placeholder="请选择是否危废企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十五行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否重点排污企业：" prop="isggarbagedisplant">
              <el-select
                v-model="formData.isggarbagedisplant"
                placeholder="请选择是否重点排污企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否辐射企业：" prop="isradiation">
              <el-select
                v-model="formData.isradiation"
                placeholder="请选择是否辐射企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十六行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否废气企业：" prop="ifwasgas">
              <el-select
                v-model="formData.ifwasgas"
                placeholder="请选择是否废气企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否噪声企业：" prop="isnoiseent">
              <el-select
                v-model="formData.isnoiseent"
                placeholder="请选择是否噪声企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十七行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否固废企业：" prop="issolidwasteent">
              <el-select
                v-model="formData.issolidwasteent"
                placeholder="请选择是否固废企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否voc企业：" prop="isvoc">
              <el-select
                v-model="formData.isvoc"
                placeholder="请选择是否voc企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十八行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否污普企业：" prop="ifwupuent">
              <el-select
                v-model="formData.ifwupuent"
                placeholder="请选择是否污普企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否执法企业：" prop="islawenforcement">
              <el-select
                v-model="formData.islawenforcement"
                placeholder="请选择是否执法企业"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十九行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否畜牧养殖：" prop="isanimalhusbandry">
              <el-select
                v-model="formData.isanimalhusbandry"
                placeholder="请选择是否畜牧养殖"
                style="width: 100%"
              >
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否畜禽养殖：" prop="isbeastsfarm">
              <el-select
                v-model="formData.isbeastsfarm"
                placeholder="请选择是否畜禽养殖"
                style="width: 100%"
              >
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第二十行 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否涉土：" prop="ifwassoil">
              <el-select
                v-model="formData.ifwassoil"
                placeholder="请选择是否涉土"
                style="width: 100%"
              >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getEnterpriseList,
  getIndustryList,
  getBasinList,
  getRiverList,
  addPollutionsource,
  editPollutionsource,
  removePollutionsource,
  pollutionsourceExport,
} from "./api";
import { getRegionList } from "@/api/dataResources/monitorData/region.js";
export default {
  name: "PollutionSourceManagement",
  dicts: ["sys_pollutions_type", "company_status", "company_type"],
  data() {
    return {
      // 查询参数
      queryParams: {
        pollutename: "",
        countycode: "",
        waterrelate: "",
        isonlinemonitoringent: "",
        issewagefarm: "",
        enterprisetype: "",
        outpermitnb: "",
        socialcode: "",
      },

      // 表格数据
      tableData: [],

      // 行政区划列表
      regionList: [],
      // 行业类型列表
      industryList: [],
      // 流域列表
      basinList: [],
      // 河流列表
      riverList: [],
      // 污水去向
      destinationList: [
        { label: "排入河流", value: "1" },
        { label: "排入污水处理厂", value: "2" },
      ],

      // 分页相关
      currentPage: 1,
      pageSize: 10,
      total: 0,

      // 选中行数据
      selectedRows: [],
      dialogVisible: false,
      formData: {},
      rules: {
        pollutename: [
          { required: true, message: "请输入污染源名称", trigger: "blur" },
        ],
        socialcode: [
          {
            required: true,
            message: "请输入统一社会信用代码",
            trigger: "blur",
          },
        ],
        longitude: [{ required: true, message: "请输入经度", trigger: "blur" }],
        latitude: [{ required: true, message: "请输入纬度", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getRegionList();
    this.getBasinList();
    this.getRiverList();
    this.getIndustryList();
    this.handleQuery();
  },

  methods: {
    formChange(value, key, map, list) {
      let item = list.find((it) => it[key] == value);
      if (item) {
        for (let fkey in map) {
          this.formData[fkey] = item[map[fkey]];
          console.log("fkey", fkey, this.formData[fkey]);
        }
      }
    },
    async getBasinList() {
      let res = await getBasinList();
      if (res.code === 200) {
        this.basinList = res.rows;
      }
    },
    async getRiverList() {
      let res = await getRiverList();
      if (res.code === 200) {
        this.riverList = res.rows;
      }
    },
    async getRegionList() {
      let res = await getRegionList(0);
      if (res.code === 200) {
        this.regionList = res.rows;
      }
    },
    async getIndustryList() {
      let res = await getIndustryList();
      if (res.code === 200) {
        this.industryList = res.rows;
      }
    },
    // 查询
    async handleQuery() {
      let params = {
        ...this.queryParams,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      };
      let res = await getEnterpriseList(params);
      this.total = 0;
      if (res.code === 200) {
        this.tableData = res.rows;
        this.total = res.total;
      }
      // 这里可以调用API获取数据
      // this.fetchData();
    },

    // 重置查询条件
    resetQuery() {
      this.queryParams = {
        pollutename: "",
        countycode: "",
        waterrelate: "",
        isonlinemonitoringent: "",
        issewagefarm: "",
        enterprisetype: "",
        outpermitnb: "",
        socialcode: "",
      };
      this.currentPage = 1;
      this.pageSize = 10;
      this.handleQuery();
    },

    // 新增
    handleAdd() {
      this.dialogVisible = true;
      this.formData = {
        pollutename: "",
        pollutenb: "",
        epoldname: "",
        county: "",
        countycode: "",
        polluteaddress: "",
        watershed: "",
        socialcode: "",
        longitude: "",
        latitude: "",
        industrytypecode: "",
        industrytypename: "",
        wrylx: "",
        destination: "",
        epstatecode: "",
        epstate: "",
        establishDate: "",
        registercapital: "",
        businessnum: "",
        organizationcode: "",
        lawperson: "",
        linkman: "",
        telephone: "",
        outpermitnb: "",
        riverid: "",
        rivername: "",
        waterrelate: "",
        isonlinemonitoringent: "",
        issewagefarm: "",
        sewageFarm: "",
        ifrisk: "",
        ishazardouswaste: "",
        isggarbagedisplant: "",
        isradiation: "",
        ifwasgas: "",
        isnoiseent: "",
        issolidwasteent: "",
        isvoc: "",
        ifwupuent: "",
        islawenforcement: "",
        isanimalhusbandry: "",
        isbeastsfarm: "",
        ifwassoil: "",
      };
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let isEdit = !!this.formData.id;
          let aipFn = isEdit ? editPollutionsource : addPollutionsource;
          aipFn(this.formData).then((res) => {
            if (res.code == 200) {
              this.$message.success("操作成功");
            }
            this.dialogVisible = false;
            this.handleQuery();
          });
        }
      });
    },
    // 删除
    handleDelete(row) {
      let ids = [];
      if (row) {
        ids.push(row.id);
      } else {
        this.selectedRows.forEach((row) => {
          ids.push(row.id);
        });
      }
      console.log("ids: ", ids);
      if (ids.length == 0) {
        this.$message.warning("请先选择要删除的数据");
        return;
      }
      this.$confirm("确定要删除选中的数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let idsStr = ids.join(",");
          removePollutionsource(idsStr).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.handleQuery();
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    },

    // 导出
    handleExport() {
      let url = pollutionsourceExport(this.queryParams);
      // console.log('url: ', url);
      // const filePath = `${url}`;
      return;

      // 创建下载链接
      const link = document.createElement("a");
      link.href = filePath;
      link.download = "污染源信息导出";
      link.style.display = "none";

      // 添加到页面并触发下载
      document.body.appendChild(link);
      link.click();
      // 清理
      document.body.removeChild(link);
    },

    // 导入
    handleImport() {
      this.$message.info("点击导入按钮");
    },

    // 下载模板
    downloadTemplate() {
      this.$message.info("点击下载模板按钮");
    },

    // 处理表格选中变化
    handleSelectionChange(val) {
      this.selectedRows = val;
    },

    // 处理每行的修改
    handleEditRow(row) {
      this.formData = { ...row };
      this.dialogVisible = true;
    },

    // 分页大小改变
    handleSizeChange(val) {
      this.pageSize = val;
      this.handleQuery();
    },

    // 当前页改变
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handleQuery();
    },
  },
};
</script>

<style scoped>
#panel {
  padding: 20px;
}

.demo-form-inline {
  margin-bottom: 15px;
}

.el-form-item {
  margin-right: 10px;
}

.el-button {
  margin-right: 10px;
}

.el-table {
  margin-bottom: 20px;
}

.pagination-container {
  margin-top: 20px;
  text-align: right;
}
</style>
